//
//  RentHouseHomeVC.m
//  CenturyCity
//
//  Created by beisheng03 on 2017/12/18.
//  Copyright © 2017年 beisheng. All rights reserved.
//

#import "RentHouseHomeVC.h"
#import "RentHouseNavView.h"
//#import "RenHouseTopImageCell.h"
#import "RenHouseCategoryCell.h"
#import "RenHouseHomeListCell.h"
#import <DOPDropDownMenu.h>
#import "RentHouseDetailVC.h"
#import "HouseListParameter.h"
#import "HousRentAdvsModel.h"
#import "HouseParameterModel.h"
#import "HouseParameSub.h"
#import "ProvinceModel.h"
#import "CitysModel.h"
#import "DistrictsModel.h"
#import "RenHouseTopMenu.h"

#import "ZMSearchController.h"
#import "BaseNavigationController.h"

@interface RentHouseHomeVC ()<DOPDropDownMenuDataSource,DOPDropDownMenuDelegate>
/** <#note#> */
@property (nonatomic, strong) RentHouseNavView *headerView;

@property (nonatomic, assign) NSInteger curpage;

@property (nonatomic, assign) NSString *pageCount;

@property (nonatomic, assign) NSString *totalCount;

@property (nonatomic, strong) NSMutableArray<HouseParameterModel *> *dataModels;

@property (nonatomic, strong) NSMutableArray<HousRentAdvsModel *> *ADVSModels;


@property (nonatomic, weak) DOPDropDownMenu *menu;


@property (nonatomic, strong) HouseListParameter *dataParameters;


@property (nonatomic, assign) CGFloat topViewH;


@property (nonatomic, weak) UIView *navLineView;


@property (nonatomic, assign) CGFloat menuTop;

/**
 *  记录下最开始的y轴偏移量
 */
@property (nonatomic, assign) CGFloat oriOffsetY;


@property (nonatomic, assign) CGFloat dorH;


//@property (nonatomic, strong) NSString *menuTag;


@property (nonatomic, strong) RenHouseTopMenu *topView;


@end


#define kHeadViewH 200
#define kHeadViewMinH 64

@implementation RentHouseHomeVC



- (RenHouseTopMenu *)topView{
    
    if (!_topView) {
        
        RenHouseTopMenu *temp = (RenHouseTopMenu *)[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([RenHouseTopMenu class]) owner:nil options:nil].firstObject;
        CGFloat navH = IPhoneX ? 88 : 64;
        
        temp.frame = CGRectMake(0, 0, KScreenW, 142 + navH);
        
//        temp.backgroundColor = [UIColor redColor];
        
//        [temp.topBtn setTitle:@"立即支付" forState:UIControlStateNormal];
//        [temp.topBtn setTitle:@"立即支付" forState:UIControlStateHighlighted];
//
//        [temp.topBtn addTarget:self action:@selector(gotoOderPage) forControlEvents:UIControlEventTouchUpInside];
        
        _topView = temp;
        
        [self.view addSubview:temp];
        
    }
    
    return _topView;
}

- (HouseListParameter *)dataParameters{
    
    if (!_dataParameters) {
        
        _dataParameters = [[HouseListParameter alloc]init];
        
    }
    
    return _dataParameters;
}



- (DOPDropDownMenu *)menu{
    if (!_menu) {
        
        // 添加下拉菜单
        DOPDropDownMenu *menu = [[DOPDropDownMenu alloc] initWithOrigin:CGPointMake(0, self.topView.height - 45) andHeight:45];
        menu.delegate = self;
        menu.dataSource = self;
        menu.isClickHaveItemValid = NO;
        [self.view addSubview:menu];
        
        self.menu = menu;
        
        [menu selectIndexPath:[DOPIndexPath indexPathWithCol:0 row:0 item:0]];
    }
    
    
    
    return _menu;
}



- (RentHouseNavView *)headerView{
    
    if (!_headerView) {
        
        RentHouseNavView *temp = (RentHouseNavView *)[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([RentHouseNavView class]) owner:nil options:nil].firstObject;
        
         CGFloat viewH = IPhoneX ? 88 : 64;
        
        temp.frame = CGRectMake(0, 0, KScreenW, viewH);
        
        UIButton *btn = [temp viewWithTag:22];
        
        btn.imageView.contentMode = UIViewContentModeScaleAspectFit;
        
        
        btn.contentEdgeInsets = UIEdgeInsetsMake(11, 10, 11, 10);
        
        [btn addTarget:self action:@selector(popCurrentController) forControlEvents:UIControlEventTouchUpInside];
        
        
        UIButton *btn2 = [temp viewWithTag:33];
        btn2.layer.cornerRadius = 5;
        
        btn2.layer.masksToBounds = YES;
        
        self.navLineView = [temp viewWithTag:11];
        
        self.navLineView.backgroundColor = [UIColor clearColor];
        
        _headerView = temp;
        
//        btn.hidden = YES;
        
        
        
//        [self.view addSubview:temp];
        
    }
    
    return _headerView;
}





- (void)popCurrentController{
    
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
//    self.navigationItem.title = @"租房";

    self.groupTableView.tableFooterView = [[UIView alloc]init];
    self.groupTableView.separatorInset = UIEdgeInsetsZero;
    self.groupTableView.backgroundColor = [UIColor whiteColor];
    
    [self.groupTableView registerClass:[BaseTableViewCell class] forCellReuseIdentifier:[BaseTableViewCell identifierStr]];
    
//    [self.groupTableView registerNib:[UINib nibWithNibName:NSStringFromClass([RenHouseTopImageCell class]) bundle:nil] forCellReuseIdentifier:[RenHouseTopImageCell identifierStr]];
//    [self.groupTableView registerNib:[UINib nibWithNibName:NSStringFromClass([RenHouseCategoryCell class]) bundle:nil] forCellReuseIdentifier:[RenHouseCategoryCell identifierStr]];
     [self.groupTableView registerNib:[UINib nibWithNibName:NSStringFromClass([RenHouseHomeListCell class]) bundle:nil] forCellReuseIdentifier:[RenHouseHomeListCell identifierStr]];
    
    
  
    
//
    
    self.topView.backgroundColor = viewBgGrey;

    
    self.headerView.backgroundColor = themeColor;
//    self.headerView.hidden = YES;
    
    
    self.menu.backgroundColor = [UIColor whiteColor];;
    
    MJWeakSelf
    self.groupTableView.mj_header = [XMGRefreshHeader headerWithRefreshingBlock:^{
        
        [weakSelf loadData];
        
    }];
    
    [weakSelf.groupTableView.mj_header beginRefreshing];
    
    
    self.groupTableView.mj_footer = [XMGRefreshFooter footerWithRefreshingBlock:^{
        [weakSelf loadMoreData];
    }];
    
    
    
    
  
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(WXApiDidSuccessNotification) name:WXApiDidSuccessNotification object:nil];
    
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(AlipayDidSuccessNotification) name:AlipayDidSuccessNotification object:nil];
    
    
    self.automaticallyAdjustsScrollViewInsets = NO;

    //    CGFloat navH = IPhoneX ? 44 : 20;
    CGFloat navH = IPhoneX ? 88 : 64;
    CGFloat tabbarH = IPhoneX ? 83 : 49;

    if (@available(iOS 11.0, *)) {
        //        contentInsetAdjustmentBehavior属性也是用来取代automaticallyAdjustsScrollViewInsets属性的，推荐使用这种方式。
        self.groupTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;

        self.groupTableView.contentInset = UIEdgeInsetsMake(navH + 142, 0, tabbarH, 0);

    }else{

        self.groupTableView.contentInset = UIEdgeInsetsMake(navH + 142, 0, tabbarH, 0);

    }
    
    [self setNavView];
    
    
    
}

- (void)setNavView{
    
    UIView *navLeftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 44)];
    
//    navLeftView.backgroundColor = [UIColor orangeColor];

    UIButton *but = [UIButton buttonWithType:UIButtonTypeCustom];
    [but setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
    [but setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateHighlighted];
    
    [but addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    
    
    but.imageView.contentMode = UIViewContentModeScaleAspectFit;
    
//    but.backgroundColor = [UIColor purpleColor];
    
//    but.backgroundColor = [UIColor redColor];
    
    but.frame = CGRectMake(-5, 0, 25, 44);
    
    but.contentEdgeInsets = UIEdgeInsetsMake(11, 0, 11, 0);
    
    [navLeftView addSubview:but];
    
    UIBarButtonItem *returnButtonItem = [[UIBarButtonItem alloc]initWithCustomView:navLeftView];
    
//    self.navigationController.navigationItem.leftBarButtonItem = returnButtonItem;
    
    self.navigationItem.leftBarButtonItem = returnButtonItem;
    
    UIView * navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenW - 62, 44)];
    
//    bg_search_bar_7_write
//    navView.backgroundColor = [UIColor redColor];
    
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    btn.layer.cornerRadius = 3;
    
    btn.layer.masksToBounds = YES;
    
    [btn setBackgroundImage:[UIImage imageNamed:@"bg_search_bar_7_write"] forState:UIControlStateNormal];
    
    [btn setBackgroundImage:[UIImage imageNamed:@"bg_search_bar_7_write"] forState:UIControlStateHighlighted];
    
    btn.frame = CGRectMake(0, 6, KScreenW - 62, 31);
    
    [btn addTarget:self action:@selector(rightBtnDidTap:) forControlEvents:UIControlEventTouchUpInside];
    

    [navView addSubview:btn];
    
    
    UITextField *textf = [[UITextField alloc]initWithFrame:CGRectMake(25, 0, KScreenW - 62, 44)];
    
    textf.placeholder = @"请输入小区或街道名称";
    
    textf.font = MYFONT(14);
    
    textf.userInteractionEnabled = NO;
    
    [navView addSubview:textf];

    self.navigationItem.titleView = navView;
    
}




- (void)rightBtnDidTap:(UIButton *)sender {
    
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 15, 10, 15);
    
    flowLayout.minimumLineSpacing = 10;
    
    flowLayout.minimumInteritemSpacing = 10;
    
    ZMSearchController *temp = [[ZMSearchController alloc]initWithCollectionViewLayout:flowLayout];
    
    temp.type = @"4";
    
    BaseNavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:temp];
    
    [self presentViewController:nav animated:YES completion:nil];
    
}


- (void)back{
    
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    
    
}



- (void)WXApiDidSuccessNotification{
    
    [self loadData];
}



- (void)AlipayDidSuccessNotification{
    
   [self loadData];
    
}




- (void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    
}



/**
 * 房源列表接口
 * page                 当前第几页 （默认1）
 * pagesize             每页数据总条数（默认10）
 * languageId           语种id
 * provinceId           所在区域一级地区
 * cityId               所在区域二级地区
 * payClassId           付款方式id
 * rentingStyleId       租房方式id
 
 */

- (void)loadData{
    
    
    self.curpage = 1;
    
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"page"] = @"1";
    parameters[@"pagesize"] = @"20";
    
    if (self.dataParameters.languageId.length > 0) {
        parameters[@"languageId"] = self.dataParameters.languageId;

    }
    
    if (self.dataParameters.provinceId.length > 0) {
        parameters[@"provinceId"] = self.dataParameters.provinceId;
        
    }
    
    if (self.dataParameters.cityId.length > 0) {
        parameters[@"cityId"] = self.dataParameters.cityId;
        
    }
    
    if (self.dataParameters.payClassId.length > 0) {
        parameters[@"payClassId"] = self.dataParameters.payClassId;
        
    }
    

    
    
    MJWeakSelf;
    [[NetworkTools shareNetworkTools]sendRequestWithHttpMethod:GET_METHOD URLPath:@"house/lists" parameters:parameters completionHandler:^(id responseObject, NSError *error) {
        
        if (!error) {
            
//            MYJSONSTR
            //            _model.lastString
            
            //           [[responseObject[@"data"][@"house"] firstObject]  propertyCode];
            
            weakSelf.pageCount = responseObject[@"data"][@"page_count"];
            
            weakSelf.totalCount = responseObject[@"data"][@"total_count"];
            
          weakSelf.ADVSModels = [NSMutableArray array];
            

//            weakSelf.ADVSModels
//            [weakSelf.ADVSModels removeAllObjects];
            weakSelf.dataModels = [HouseParameterModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"house"]];
            
            if (myViewModel.parameterModel != nil) {
                for (HouseParameterModel *model in weakSelf.dataModels) {
                    
                    model.language = myViewModel.parameterModel.language;
                    model.huxing = myViewModel.parameterModel.huxing;
                    model.fukuan = myViewModel.parameterModel.fukuan;
                    model.rentingStyle = myViewModel.parameterModel.rentingStyle;
                    model.decorateStyle = myViewModel.parameterModel.decorateStyle;
                    model.houseStyle = myViewModel.parameterModel.houseStyle;
                    model.position = myViewModel.parameterModel.position;
                    
                    [weakSelf setupValues:model];
                }
            }
            
            
            [weakSelf.groupTableView.mj_footer resetNoMoreData];
            
//            weakSelf.menu.hidden = NO;
            
            NSLog(@"%@",weakSelf.totalCount);
            
            if ([weakSelf.totalCount isEqualToString:@"0"]) {
                
                [weakSelf.groupTableView.mj_footer endRefreshingWithNoMoreData];

            } else {
                
                if ([weakSelf.pageCount isEqualToString:@"1"]) {
                    
                    [weakSelf.groupTableView.mj_footer endRefreshingWithNoMoreData];
                    
                }
            }
            
            
   
                

            [weakSelf.groupTableView.mj_header endRefreshing];
                    
            [weakSelf.groupTableView reloadData];
              
                
              
  
            
 
            
            
        } else {
            
            [weakSelf.groupTableView.mj_header endRefreshing];
            
            [SVProgressHUD showInfoWithStatus:error.domain];
            
        }
    }];
    
    
    
    
    
    
    
    
    
    
}



- (void)downloadImage{
    
    dispatch_group_t group = dispatch_group_create();
    
    
//    self.ADVSModels.firstObject.adv_image = @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1515323504845&di=c1876d06c8ed15b64d10cc4dc54fe429&imgtype=0&src=http%3A%2F%2Fa3.att.hudong.com%2F42%2F78%2F01300309316150135156788297518.jpg";
        dispatch_group_enter(group);
        [[SDWebImageManager sharedManager] downloadImageWithURL:[NSURL URLWithString:self.ADVSModels.firstObject.adv_image] options:kNilOptions progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
            
            NSLog(@"111111111");
            
            dispatch_group_leave(group);
            
        }];
   
    
    
    
    
    MJWeakSelf;
    
    dispatch_group_notify(group, dispatch_get_main_queue(), ^{
        
        
        UIImage *image0 = [[[SDWebImageManager sharedManager] imageCache] imageFromDiskCacheForKey:weakSelf.ADVSModels.firstObject.adv_image];
        
        
        
        if (image0) {
            
            CGFloat imageViewH = KScreenW / image0.size.width * image0.size.height;
            // 重置放大缩小的比例
            weakSelf.topViewH = imageViewH;
            
            
        } else {
            
            MJWeakSelf;
            [[SDWebImageManager sharedManager] downloadImageWithURL:[NSURL URLWithString:weakSelf.ADVSModels.firstObject.adv_image] options:kNilOptions progress:^(NSInteger receivedSize, NSInteger expectedSize) {
                
            } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
                
                if (image) {
                    
                    CGFloat imageViewH2 = KScreenW / image.size.width * image.size.height;
                    // 重置放大缩小的比例
                    weakSelf.topViewH = imageViewH2;
                    
                   
                    
                }else{
                    
                    weakSelf.topViewH = KScreenW / 16.0 * 9.0;

                    
                }
                
                
            }];
        }
        
    


            [weakSelf.groupTableView.mj_header endRefreshing];
            
            [weakSelf.groupTableView reloadData];
            
     
        
        
    });
    
    
    
    
}


- (void)loadMoreData{
    
    
    
    self.curpage ++;
    
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"pagesize"] = @"20";
    parameters[@"page"] = [NSString stringWithFormat:@"%ld",(long)self.curpage];
    
    if (self.dataParameters.languageId.length > 0) {
        parameters[@"languageId"] = self.dataParameters.languageId;
        
    }
    
    if (self.dataParameters.provinceId.length > 0) {
        parameters[@"provinceId"] = self.dataParameters.provinceId;
        
    }
    
    if (self.dataParameters.cityId.length > 0) {
        parameters[@"cityId"] = self.dataParameters.cityId;
        
    }
    
    if (self.dataParameters.payClassId.length > 0) {
        parameters[@"payClassId"] = self.dataParameters.payClassId;
        
    }
    
    MJWeakSelf;
    [[NetworkTools shareNetworkTools] sendRequestWithHttpMethod:GET_METHOD URLPath:@"house/lists" parameters:parameters completionHandler:^(id responseObject, NSError *error) {
        
        if (!error) {
            
//            MYJSONSTR;
            
//            weakSelf.ADVSModels = [HousRentAdvsModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"advs"]];
            
            
            
            NSMutableArray<HouseParameterModel *> *temp = [HouseParameterModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"house"]];
            
            
            
            if (myViewModel.parameterModel != nil) {
                
                for (HouseParameterModel *model in temp) {
                    
                    model.language = myViewModel.parameterModel.language;
                    model.huxing = myViewModel.parameterModel.huxing;
                    model.fukuan = myViewModel.parameterModel.fukuan;
                    model.rentingStyle = myViewModel.parameterModel.rentingStyle;
                    model.decorateStyle = myViewModel.parameterModel.decorateStyle;
                    model.houseStyle = myViewModel.parameterModel.houseStyle;
                    model.position = myViewModel.parameterModel.position;
                    
                    [weakSelf setupValues:model];
                    
                }
            }
            
            
            [weakSelf.dataModels addObjectsFromArray:temp];
            
            

            
            
            
            
            if (weakSelf.pageCount.integerValue == self.curpage) {
                
                [weakSelf.groupTableView.mj_footer endRefreshingWithNoMoreData];
                
            } else {
                
                [weakSelf.groupTableView.mj_footer endRefreshing];
                
                
            }
            
            
            [weakSelf.groupTableView reloadData];
            
        }else{
            
            [weakSelf.groupTableView.mj_footer endRefreshing];
            
            [SVProgressHUD showInfoWithStatus:error.domain];
            
        }
        
    }];
    
    
    
    
    
}




- (void)setupValues:(HouseParameterModel *)model{
    
    
    
    for (HouseParameSub *sub1 in model.position) {
        if ([sub1.class_id isEqualToString:model.house_face]) {
            model.house_face_name = sub1.name;
        }
    }
    
    
    
    
//    for (HouseParameSub *sub2 in model.language) {
//        if ([sub2.class_id isEqualToString:model.house_language]) {
//            model.house_language_name = sub2.name;
//        }
//    }
    
    
    for (HouseParameSub *sub2 in model.decorateStyle) {
        if ([sub2.class_id isEqualToString:model.house_decorate]) {
            model.house_decorate_name = sub2.name;
        }
    }
    
    
    
    
    
    
    
    
    
}








- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    if (self.dataModels == nil) {
        return 0;
    } else {
        return 1;
    }
    
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    if (self.dataModels == nil) {
        return 0;
    } else {
        return self.dataModels.count;
    }
    
 
    

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    RenHouseHomeListCell *cell = [tableView dequeueReusableCellWithIdentifier:[RenHouseHomeListCell identifierStr]];
    
    cell.model = self.dataModels[indexPath.row];
    
    return cell;
    

    
    
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
  return 124;
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0.00001;
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    

        return 0.00001;
    
    
    
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    return [[UIView alloc]init];
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    return [[UIView alloc]init];
    
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
 
        [[NSNotificationCenter defaultCenter]postNotificationName:@"putAwayView" object:nil];

        RentHouseDetailVC *temp = [[RentHouseDetailVC alloc]init];
        
        temp.houseId = self.dataModels[indexPath.row].house_id;
        
        [self.navigationController pushViewController:temp animated:YES];
   

    
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




#pragma mark - scrollView代理方法
// 监听用户的滚动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    
//    return;
    [[NSNotificationCenter defaultCenter]postNotificationName:@"putAwayView" object:nil];

    if (self.ADVSModels.count == 0){
        

        return;
    }
    // 获取当前最新偏移量
    CGFloat offsetY = scrollView.contentOffset.y;
    
//    self.menu.top = self.dorH - offsetY  ;

    

    
    if (offsetY > 0) {
        // 计算下最新偏移量和最初偏移量的差值
        // 就是用户滚动的区域
        CGFloat delta = offsetY - _oriOffsetY;
        
        // 移动头部视图
        //    _headViewYCons.constant = 0 - delta;
        // 修改头部视图的高度
        
        CGFloat headH = kHeadViewH - delta;
        if (headH < kHeadViewMinH) {
            headH = kHeadViewMinH;
        }
        
        // 处理导航条
        // 计算当前的透明度
        CGFloat alpha = delta / (kHeadViewH - kHeadViewMinH);
        
        if (alpha > 1) {
            alpha = 1;
        }
        
        
        
        // 设置标题的文字颜色
        //    _titleLabel.textColor = [UIColor colorWithWhite:0 alpha:alpha];
        
        // 获取导航条的颜色
        //    UIColor *navColor = [UIColor colorWithWhite:1 alpha:alpha];
        
        self.navLineView.backgroundColor = colorWithA(226, 226, 226,alpha);
        
        
        
        self.headerView.backgroundColor = colorWithA(23, 77, 237, alpha);
        
    } else {
        
        offsetY = - offsetY;
        
        // 计算下最新偏移量和最初偏移量的差值
        // 就是用户滚动的区域
        CGFloat delta = offsetY - _oriOffsetY;
        
        // 移动头部视图
        //    _headViewYCons.constant = 0 - delta;
        // 修改头部视图的高度
        
        CGFloat viewH = IPhoneX ? 172 : 128;
        CGFloat headH = viewH - delta;
        if (headH < kHeadViewMinH) {
            headH = kHeadViewMinH;
        }
        
        // 处理导航条
        // 计算当前的透明度
        CGFloat alpha = delta / (viewH - kHeadViewMinH);
        
        if (alpha > 1) {
            alpha = 1;
        }
        
        
        
        // 设置标题的文字颜色
        //    _titleLabel.textColor = [UIColor colorWithWhite:0 alpha:alpha];
        
        // 获取导航条的颜色
        //    UIColor *navColor = [UIColor colorWithWhite:1 alpha:alpha];
        
        self.navLineView.backgroundColor = colorWithA(226, 226, 226,alpha);
        
        
        
        self.headerView.backgroundColor = colorWithA(23, 77, 237, alpha);
        
        
        
    }
    
  

}






#pragma mark - actions

- (NSInteger)numberOfColumnsInMenu:(DOPDropDownMenu *)menu
{
    return 3;
}

- (NSInteger)menu:(DOPDropDownMenu *)menu numberOfRowsInColumn:(NSInteger)column
{
    
    
    if (column == 0) {
        
        return myViewModel.parameterModel.language.count + 1;
        
        
    }else if (column == 1){
        
        return myViewModel.areas.count + 1;
        
    }else {
        return myViewModel.parameterModel.fukuan.count + 1;
    }
}

- (NSString *)menu:(DOPDropDownMenu *)menu titleForRowAtIndexPath:(DOPIndexPath *)indexPath
{
    if (indexPath.column == 0) {
        
        if (indexPath.row == 0) {
            return @"全部语种";
        } else {
            return myViewModel.parameterModel.language[indexPath.row - 1].name;

        }
        
 

      
    
        
    } else if (indexPath.column == 1){
        
        if (indexPath.row == 0) {
            return @"全部区域";
        } else {
            return myViewModel.areas[indexPath.row - 1].province_name;
        }
            
        

        
        
    } else {
        
        if (indexPath.row == 0) {
            return @"全部方式";
        } else {
            return myViewModel.parameterModel.fukuan[indexPath.row - 1].name;

        }
        
            

        

    }
}



- (NSInteger)menu:(DOPDropDownMenu *)menu numberOfItemsInRow:(NSInteger)row column:(NSInteger)column
{
    
    if (column == 1) {
        
        if (row == 0) {
            return 1;
        } else {
            return myViewModel.areas[row - 1].citys.count;

        }
        
   
       
    
        

        
    } else {
        
        return 0;
    }

    
}

- (NSString *)menu:(DOPDropDownMenu *)menu titleForItemsInRowAtIndexPath:(DOPIndexPath *)indexPath
{

    
    if (indexPath.column == 1) {
        
        if (indexPath.row == 0) {
            
            return @"全部区域";

        } else {
            
            return myViewModel.areas[indexPath.row - 1].citys[indexPath.item].city_name;

        }
        
        
      
        
    } else {
        
        return @"";
        
    }

    
    
}


- (void)menu:(DOPDropDownMenu *)menu didSelectRowAtIndexPath:(DOPIndexPath *)indexPath
{
//    [self.view bringSubviewToFront:self.headerView];
//    NSLog(@"点击了。。。。");
    
//    return;
    if (indexPath.column == 0) {
        
        if (indexPath.row == 0) {
            
            self.dataParameters.languageId = nil;
            
        } else {
            
            HouseParameSub *sub =  myViewModel.parameterModel.language[indexPath.row - 1];
            
            self.dataParameters.languageId = sub.class_id;
        }
        
       
        
        
        
    }else if (indexPath.column == 1){
        
        if (indexPath.row == 0) {
            
            self.dataParameters.provinceId = nil;
            self.dataParameters.cityId = nil;

        } else {
            
            ProvinceModel *provice =  myViewModel.areas[indexPath.row - 1];
            
            self.dataParameters.provinceId = provice.province_id;
            
            CitysModel *cityMode = provice.citys[indexPath.item];
            
            self.dataParameters.cityId = cityMode.city_id;
            
        }
        

        
    }else {
        
        
        if (indexPath.row == 0) {
            
            self.dataParameters.payClassId = nil;

        } else {
            
            HouseParameSub *sub =  myViewModel.parameterModel.fukuan[indexPath.row - 1];
            
            self.dataParameters.payClassId = sub.class_id;
        }
        
 

        
    }
    
    
    [self loadData];
    
}


@end
